package de.QuizCommunity.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpParams;

import de.QuizCommunity.domain.Benutzer;

public class Benutzer_Put {

	public static void postBenutzer(Benutzer bn) {
		// Create a new HttpClient and Post Header
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost = new HttpPost(
				"http://www.iwi.hs-karlsruhe.de/ebatc/QuizCommunity/rest/webservice/benutzer");

		try {
			// Add your data

			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
			nameValuePairs.add(new BasicNameValuePair("id", ""
					+ bn.getIdBenutzer()));
			nameValuePairs.add(new BasicNameValuePair("benutzername", bn
					.getBenutzername()));
			nameValuePairs.add(new BasicNameValuePair("password", bn
					.getPasswort()));
			nameValuePairs.add(new BasicNameValuePair("eMail", bn.getEMail()));
			nameValuePairs.add(new BasicNameValuePair(
					"richtig_beantwortete_Fragen", ""
							+ bn.getRichtig_beantwortete_Fragen()));
			nameValuePairs.add(new BasicNameValuePair("fragen_eingestellt", ""
					+ bn.getFregenEingestellt()));
			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			httppost.setHeader("Content-type",
					"application/x-www-form-urlencoded; charset=UTF8");

			// Execute HTTP Post Request
			HttpResponse response = httpclient.execute(httppost);

		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
		} catch (IOException e) {
			// TODO Auto-generated catch block
		}
	}
	public static void putBenutzer(int id,int wert ) {
		// Create a new HttpClient and Post Header
		HttpClient httpclient = new DefaultHttpClient();
		HttpPut httpput = new HttpPut(
				"http://www.iwi.hs-karlsruhe.de/ebatc/QuizCommunity/rest/webservice/benutzer/update");

		try {
			// Add your data

			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
			nameValuePairs.add(new BasicNameValuePair("id", ""+id));
			nameValuePairs.add(new BasicNameValuePair("wert",""+wert));
			httpput.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			httpput.setHeader("Content-type",
					"application/x-www-form-urlencoded; charset=UTF8");

			// Execute HTTP Post Request
			HttpResponse response = httpclient.execute(httpput);

		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
		} catch (IOException e) {
			// TODO Auto-generated catch block
		}
	}
}
